/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.analysis.marcxml;

import cz.mzk.oai.metadataRepository.Tools;
import cz.mzk.oai.metadataRepository.metadata.MarcRecord;
import cz.mzk.oai.metadataRepository.metadata.MultipleDataField;
import cz.mzk.oai.metadataRepository.tools.FileTools;
import java.io.File;
import java.io.FileNotFoundException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;

/**
 * Extension of MarcRecord that contains also those datafields and controlfields, that are not needed in actual metadata processin.
 * These fields are good for analysis of number of records.
 * @author Martin Rehanek, Martin.Rehanek@gmail.com
 */
public class AnalyticMarcRecord extends MarcRecord {

    private MultipleDataField datafield040 = null;

    public AnalyticMarcRecord(File inFile) throws DocumentException, FileNotFoundException {
        super();
        this.id = Tools.filenameToId(inFile.getName());
        Document doc = FileTools.loadDocument(inFile);
        init();
        loadDoc(doc);
    }

    public AnalyticMarcRecord(Document doc, String id) {
        this.id = id;
        init();
        loadDoc(doc);
    }

    @Override
    protected void init() {
        super.init();
        datafield040 = new MultipleDataField(2);
    }

    @Override
    protected void analyzeDatafieldElement(Element element) {
        super.analyzeDatafieldElement(element);
        analyzeElement(element, "040", new char[]{'b'}, datafield040);
    }

    @Override
    protected void analyzeControlfieldElement(Element element) {
        super.analyzeControlfieldElement(element);

    }

    public MultipleDataField getDatafield040() {
        return datafield040;
    }
}
